{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "angle 64.12065894585056\n",
      "captured one image\n",
      "VLM set\n",
      "angle 78.12065894585056\n",
      "captured one image\n",
      "VLM set\n",
      "angle 92.12065894585056\n",
      "captured one image\n",
      "VLM set\n",
      "angle 106.12065894585055\n",
      "captured one image\n",
      "VLM set\n",
      "angle 120.12065894585055\n",
      "captured one image\n",
      "VLM set\n",
      "node expanded\n",
      "node expanded\n",
      "node expanded\n",
      "node expanded\n",
      "node expanded\n",
      "Given scene descriptions: ['This scene features a park, likely an urban park area, with a curb pavement. You see a bicycle, a car, a meter parking meter, and a pole to your front', 'This scene features a park, likely an urban park area, with a curb pavement. You see a bicycle, a car, a meter parking meter, and a pole to your front', 'This scene features a park, likely an urban park area, with a curb pavement. You see a bicycle, a car, a meter parking meter, and a pole to your front', 'This scene features a park, likely an urban park area, with a curb pavement. You see a bicycle, a car, a meter parking meter, and a pole to your front', 'This scene features a park, likely an urban park area, with a curb pavement. You see a bicycle, a car, a meter parking meter, and a pole to your front']\n",
      "Abstracted description: The scene consistently depicts an urban park setting with a curb pavement. Key elements present include a bicycle, a car, a parking meter, and a pole.\n",
      "abstracted base nodes\n",
      "abstracted top nodes\n",
      "Node to rephrase: This scene features a park, likely an urban park area, with a curb pavement. You see a bicycle, a car, a meter parking meter, and a pole to your front\n",
      "Using global context: ['The scene consistently depicts an urban park setting with a curb pavement. Key elements present include a bicycle, a car, a parking meter, and a pole.']\n",
      "Rephrased description: The scene predominantly portrays an urban park setting, distinguished by its curb pavement. Prominent features within this landscape encompass a bicycle, a car, a parking meter, and a pole.\n",
      "Node to rephrase: This scene features a park, likely an urban park area, with a curb pavement. You see a bicycle, a car, a meter parking meter, and a pole to your front\n",
      "Using global context: ['The scene consistently depicts an urban park setting with a curb pavement. Key elements present include a bicycle, a car, a parking meter, and a pole.']\n",
      "Rephrased description: 'The scene is set in a consistent urban park ambiance, complete with a curb pavement. It is accentuated by key urban elements such as a bicycle, a car, a parking meter, and a pole, all visible in the forefront.'\n",
      "Node to rephrase: This scene features a park, likely an urban park area, with a curb pavement. You see a bicycle, a car, a meter parking meter, and a pole to your front\n",
      "Using global context: ['The scene consistently depicts an urban park setting with a curb pavement. Key elements present include a bicycle, a car, a parking meter, and a pole.']\n",
      "Rephrased description: In a consistent portrayal of an urban park setting, the scene unfolds on a paved curb. The immediate view captures key elements such as a bicycle, a car, a parking meter, and a pole, further establishing the metropolitan park ambiance.\n",
      "Node to rephrase: This scene features a park, likely an urban park area, with a curb pavement. You see a bicycle, a car, a meter parking meter, and a pole to your front\n",
      "Using global context: ['The scene consistently depicts an urban park setting with a curb pavement. Key elements present include a bicycle, a car, a parking meter, and a pole.']\n",
      "Rephrased description: The scene is accurately set in an urban park environment, characterized by the presence of a curb pavement. Prominent fixtures within this setting include a bicycle, an automobile, a parking meter, and a pole.\n",
      "Node to rephrase: This scene features a park, likely an urban park area, with a curb pavement. You see a bicycle, a car, a meter parking meter, and a pole to your front\n",
      "Using global context: ['The scene consistently depicts an urban park setting with a curb pavement. Key elements present include a bicycle, a car, a parking meter, and a pole.']\n",
      "Rephrased description: The depicted scene is set in a consistent urban park environment, characterized by a curb pavement. Prominent objects to the observer's front within this setting include a bicycle, a car, a parking meter, and a pole.\n",
      "expaned nodes rephrased\n",
      "Running MCTS\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/droplab/Research/ReasonedExplorer/examples/../src/MCTS.py:98: RuntimeWarning: coroutine 'MCTS.selection' was never awaited\n",
      "  S_t1_star, depth = self.selection(S_t1_list, 1)\n",
      "RuntimeWarning: Enable tracemalloc to get the object allocation traceback\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "cannot unpack non-iterable coroutine object",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[1], line 29\u001b[0m\n\u001b[1;32m     26\u001b[0m explorer_instance \u001b[39m=\u001b[39m Exploration(mcts_instance, X, K, N, r, fov, rom, MODEL)\n\u001b[1;32m     28\u001b[0m \u001b[39m# Run the exploration process\u001b[39;00m\n\u001b[0;32m---> 29\u001b[0m explorer_instance\u001b[39m.\u001b[39;49mexplore()\n",
      "File \u001b[0;32m~/Research/ReasonedExplorer/examples/../src/exploration.py:161\u001b[0m, in \u001b[0;36mExploration.explore\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    159\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39mRunning MCTS\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m    160\u001b[0m descriptions \u001b[39m=\u001b[39m [node\u001b[39m.\u001b[39mdescription \u001b[39mfor\u001b[39;00m node \u001b[39min\u001b[39;00m nodes]\n\u001b[0;32m--> 161\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mmcts\u001b[39m.\u001b[39;49mrun_mcts(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mk, descriptions)\n\u001b[1;32m    163\u001b[0m \u001b[39mfor\u001b[39;00m node \u001b[39min\u001b[39;00m nodes:\n\u001b[1;32m    164\u001b[0m     \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mQ_list[\u001b[39mstr\u001b[39m(node)] \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmcts\u001b[39m.\u001b[39mQ\u001b[39m.\u001b[39mget(\u001b[39mstr\u001b[39m(node\u001b[39m.\u001b[39mdescription), \u001b[39m0\u001b[39m)\n",
      "File \u001b[0;32m~/Research/ReasonedExplorer/examples/../src/MCTS.py:98\u001b[0m, in \u001b[0;36mMCTS.run_mcts\u001b[0;34m(self, K, S_t1_list)\u001b[0m\n\u001b[1;32m     95\u001b[0m \u001b[39mfor\u001b[39;00m k \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(K):\n\u001b[1;32m     96\u001b[0m     start_time \u001b[39m=\u001b[39m time\u001b[39m.\u001b[39mtime()  \u001b[39m# start timer\u001b[39;00m\n\u001b[0;32m---> 98\u001b[0m     S_t1_star, depth \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mselection(S_t1_list, \u001b[39m1\u001b[39m)\n\u001b[1;32m     99\u001b[0m     S_t2_sample \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mexpansion(S_t1_star)\n\u001b[1;32m    100\u001b[0m     pi_mean \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39msimulation(S_t2_sample)\n",
      "\u001b[0;31mTypeError\u001b[0m: cannot unpack non-iterable coroutine object"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "sys.path.append('../')\n",
    "from src.MCTS import MCTS\n",
    "from src.exploration import Exploration\n",
    "import openai\n",
    "import asyncio\n",
    "\n",
    "\n",
    "openai.api_key = \"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\"\n",
    "MODEL = \"gpt-3.5-turbo\"\n",
    "\n",
    "ETA = 0.1 # Scaling factor for exploration\n",
    "GAMMA = 0.5 # N(S_t+1)^gamma\n",
    "X = 5  # X nodes to abstract\n",
    "K = 10  # How many iterations to run MCTS at each step\n",
    "N = 5 # Action space and tree width\n",
    "L = 3  # Tree length\n",
    "r = 100 # radius of selection\n",
    "fov = 86 # Field of View\n",
    "rom = 70 # Range of motion\n",
    "\n",
    "\n",
    "goal = \"Find me a picnic table\"\n",
    "# Initialize MCTS\n",
    "mcts_instance = MCTS(ETA, GAMMA, N, L, goal, MODEL)\n",
    "\n",
    "# Initialize Exploration with the MCTS instance\n",
    "explorer_instance = Exploration(mcts_instance, X, K, N, r, fov, rom, MODEL)\n",
    "\n",
    "# Run the exploration process\n",
    "explorer_instance.explore()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Defaulting to user installation because normal site-packages is not writeable\n",
      "Collecting gmplot\n",
      "  Downloading gmplot-1.4.1-py3-none-any.whl (164 kB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m164.7/164.7 KB\u001b[0m \u001b[31m3.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
      "\u001b[?25hRequirement already satisfied: requests in /home/droplab/.local/lib/python3.10/site-packages (from gmplot) (2.31.0)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/droplab/.local/lib/python3.10/site-packages (from requests->gmplot) (1.26.16)\n",
      "Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3/dist-packages (from requests->gmplot) (3.3)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /home/droplab/.local/lib/python3.10/site-packages (from requests->gmplot) (3.2.0)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests->gmplot) (2020.6.20)\n",
      "Installing collected packages: gmplot\n",
      "Successfully installed gmplot-1.4.1\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
